var app = Common.initApp(['ngAnimate']);
Common.initDirective(app);
// File.init(app);
// Pageoffice.direcPageoffice(app);
app.controller('openOfficeController', [
    '$scope', '$http', '$templateCache',
    function ($scope, $http, $templateCache) {

        $scope.checkPageOfficeInsert = function () {
            var flag = Pageoffice.checkPageOffice();
            console.log(flag);
            if (flag) {
                $("#pageoffice-download-link").hide();
            } else {
                $("#pageoffice-download-link").show();
            }
            $("#file-load-zone").attr("src", Common.webRoot()+"/szboanda/hbdc/gwgl/fwgl/controller/fwglcontroller/file/load?businessId=" +
                $scope.YWID + "&lxdm=" + $scope.LXDM + "&zlxdm=" + $scope.ZLXDM + "&readOnly=" + $scope.readOnly);
        };

        $scope.openOnLineEditPage = function () {
            /*window.open("/web/common/pageoffice/officepagecontroller/open" +
                "?businessId=1574317730399029249536&lclx=&wjmc=测试发文在线拟稿&newFlag=true")*/
            // DOMID
            var wjmc = window.parent.$("input[ng-model='dynamic." + $scope.DOMID + "']").val();
            if (wjmc == undefined || wjmc == '') {
                Layer.showAlert("请先填写标题信息");
                return;
            }
            var dataUrl = Common.webRoot() + "/szboanda/hbdc/gwgl/fwgl/controller/customizationFileProcessController/file/info";
            var openDocumentConfig = {
                method: "POST",
                url: dataUrl,
                data: JSON.stringify({
                    YWSJID: $scope.YWID,
                    LXDM: $scope.LXDM,
                    ZLXDM: $scope.ZLXDM,
                    NEWFLAG: true,
                    WJMC: wjmc,
                    WJLX: 'docx'
                }),
                success: function (data) {
                    $scope.WJID = data.data.WJID;
                    $scope.YWSJID = data.data.YWSJID;
                    $scope.WJMC = data.data.WJMC;
                    $scope.modeType = "2";
                    $scope.openOffice();
                    $("#file-load-zone").attr("src", Common.webRoot()+"/szboanda/hbdc/gwgl/fwgl/controller/fwglcontroller/file/load?businessId=" +
                        $scope.YWID + "&lxdm=" + $scope.LXDM + "&zlxdm=" + $scope.ZLXDM + "&readOnly=" + $scope.readOnly);
                }
            };
            Common.send($scope, $http, openDocumentConfig);
        }


        $scope.openOffice = function () {
            //debugger;
            Pageoffice.openOffice($scope, $http, {
                templateId: $scope.WJID,
                ywsjId: $scope.YWSJID,
                /*beanName: 'ProjectAdapter',
                beanParams: 'obj001',*/
                fileName: $scope.WJMC,
                title: $scope.WJMC,
                modeType: $scope.modeType,
                userDefineBtns: 'buttons.history',
                showTitlebar: true,
                showSaveBtn: true,
                saveWithRevision: true,
                showAcceptRevisionBtn: true,
                showRevisionBtn: true
            });
        };

    }
]);
